// custom-tab-bar/index.js
const app = getApp()
Component({
  properties: {
    //界面显示判断，index为主页,signup为注册,mine为我的
    index: {
      type: String,
      value: '../image/tabbar/index.png'
    },
    index_HL: {
      type: String,
      value: '../image/tabbar/indexSelected.png'
    },
    signup: {
      type: String,
      value: '../image/tabbar/sign.png'
    },
    signup_HL: {
      type: String,
      value: '../image/tabbar/signSelected.png'
    },
    mine: {
      type: String,
      value: '../image/tabbar/mine.png'
    },
    mine_HL: {
      type: String,
      value: 'http://frontend.gsdse.cn/gsdkj-recruit/static/img/tab-bar-icon/mine_HL.svg?sign=1bf909a70821bfa60f6237905e4c634b&t=1657443126'
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    selected: {
      type: String,
      value: 'index'
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const that = this
      // console.log(e.currentTarget.dataset.page);
      var page = e.currentTarget.dataset.page;
      wx.switchTab({
        url: '/pages/' + page + '/' + page,
        success: function () {
          that.setData({
            selected: page
          })
        }
      })

    },
  },
  lifetimes: {
    created() {

    },
    attached() {

    },
    ready() {
      //检测图标对应的页面
      setInterval(() => {
        // 获取当前页面名称
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
        const pageName = currentPage.route.split("/")
        //修改图标状态
        this.setData({
          selected: pageName[pageName.length - 1]
        })
      },500)
    },
    moved() {

    },
    detached() {

    },
    error() {

    }
  }
})